package com.hzcx.app.simplechat.ui.chat.dialog;

import android.content.Context;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.hzcx.app.simplechat.R;
import com.hzcx.app.simplechat.base.BaseDialog;
import com.hzcx.app.simplechat.util.empty.EmptyUtils;

import butterknife.BindView;

/**
 * 群聊昵称修改
 */
public class ChatGroupNicknameDialog extends BaseDialog {
    @BindView(R.id.et_nick_name)
    EditText etNickName;
    @BindView(R.id.view_line)
    View viewLine;
    @BindView(R.id.tv_cancel)
    TextView tvCancel;
    @BindView(R.id.tv_confirm)
    TextView tvConfirm;

    private String name;
    private OnGroupNameListener listener;

    public ChatGroupNicknameDialog(@NonNull Context context,String name,OnGroupNameListener listener) {
        super(context);
        this.name=name;
        this.listener=listener;
    }

    @Override
    public int getLayout() {
        return R.layout.dialog_chat_grou_nickname;
    }

    @Override
    public void initPresenter() {

    }

    @Override
    public void initView() {
        etNickName.setText(name);

        tvCancel.setOnClickListener(view -> dismiss());

        tvConfirm.setOnClickListener(view -> {
            String newName = etNickName.getText().toString();
            if(EmptyUtils.isEmpty(newName)){
                showError("请输入昵称");
                return;
            }
            if(listener!=null){
                listener.groupName(newName);
            }
            dismiss();
        });
    }

    @Override
    public void initData() {

    }

    public interface OnGroupNameListener{
        void groupName(String name);
    }
}
